﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CvModel;
using System.Data.Entity.Migrations;
using System.Data.SqlClient;
using System.Data;


namespace DAL
{
    public class WorkAdDB
    {
        private static CvModelContainer _context = new CvModelContainer();

        //CREATE
        public static int CreateWorkAd(WorkAd workAd)
        {
            try
            {
                var query = _context.WorkAds.Add(workAd);
                return _context.SaveChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }
        //READ
        public static WorkAd GetWorkAd(int workAdId)
        {
            try
            {
                return _context.WorkAds.Where(w => w.WorkAdId == workAdId).ToList().First();
            }
            catch (Exception)
            {

                throw;
            }
        }
        //UPDATE
        public static int UpdateWorkAd(WorkAd workAd)
        {
            try
            {
                _context.WorkAds.AddOrUpdate(workAd);
                return _context.SaveChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }
        //DELETE
        public static int DeleteWorkAd(int workAdId)
        {
            try
            {
                var query =
                    (from w in _context.WorkAds
                     where w.WorkAdId == workAdId
                     select w).Single();

                _context.WorkAds.Remove(query);

                return _context.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
